using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace PoemonAdventures
{
    public enum GameState
    {
        Story,
        Menu,
        Map,
        Fight,
        Help
    }

    public class ScreenManager : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        
        public static GameState gameState;
        public static SpriteFont osdFont;
        
        MenuScreen menuScreen;
        GameScreen gameScreen;
        FightScreen fightScreen;
        HelpScreen helpScreen;
        StoryScreen storyScreen;

        public ScreenManager()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            gameState = GameState.Menu;
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            osdFont = Content.Load<SpriteFont>("basic");
            storyScreen = new StoryScreen();
            gameScreen = new GameScreen(this);
            menuScreen = new MenuScreen();
            helpScreen = new HelpScreen();
        }

        internal void Fight(FightScreen fightScreen)
        {
            this.fightScreen = fightScreen;
            gameState = GameState.Fight;
        }

        protected override void Update(GameTime gameTime)
        {
            switch (gameState)
            {
                #region StoryScreen
                case GameState.Story:
                    storyScreen.Update(gameTime);
                    break;
                #endregion
                #region MenuScreen
                case GameState.Menu:
                    menuScreen.Update(gameTime);
                    break;
                #endregion
                #region MapScreen
                case GameState.Map:
                    gameScreen.Update(gameTime);
                    break;
                #endregion
                #region FightScreen
                case GameState.Fight:
                    fightScreen.Update(gameTime);
                    break;
                #endregion
                #region HelpScreen
                case GameState.Help:
                    helpScreen.Update(gameTime);
                    break;
                #endregion
            }
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            switch (gameState)
            {
                #region StoryScreen
                case GameState.Story:
                    storyScreen.Draw(spriteBatch);
                    break;
                #endregion
                #region MenuScreen
                case GameState.Menu:
                    menuScreen.Draw(spriteBatch);
                    break;
                #endregion
                #region MapScreen
                case GameState.Map:
                    gameScreen.Draw(spriteBatch);
                    break;
                #endregion
                #region FightScreen
                case GameState.Fight:
                    fightScreen.Draw(spriteBatch);
                    break;
                #endregion
                #region HelpScreen
                case GameState.Help:
                    helpScreen.Draw(spriteBatch);
                    break;
                #endregion
            }
            base.Draw(gameTime);
        }
    }
}
